<template>
	<view class="home">
		<!-- 搜索部分 -->
		<u-search placeholder="请输入关键字" margin="10rpx" height="80" bg-color="#dfdfdf" v-model="keyword" shape="round"
		 :animAation="true" :show-action="true" @custom="change"></u-search>
		<view>
			<u-popup v-model="show" mode="bottom" border-radius="14" length="60%" :mask="false" :closeable="true" @close="close">
				<scroll-view scroll-y="true" class="Search" v-show="Search_result === false">
					<view class="Search_item" v-for="(item,index) in Search_message" :key="index" @click="nav(item.id,item.publisher_number)">
						<view class="Search_item_One">
							取快递({{item.take_item}})到{{item.give_item}}<text style="color: #FCBD71;" decode>{{space}}{{space}}金额:{{money(item.size)}}{{space}}{{space}}快递类型:{{item.type}}</text>
						</view>
						<view class="iconfont icon-jiantou Search_item_Two"></view>
					</view>
					<view style="height: 40px;"></view>
				</scroll-view>
				<view class="result" v-show="Search_result === true">
					未搜索到您要找的内容哦~
				</view>
			</u-popup>
		</view>

		<!-- 广告部分 -->
		<advers_list :advers="swipers"></advers_list>

		<!-- 导航部分 -->
		<view class="nav">
			<view class="nav_item" v-for="(item,index) in navs" :key="index" @click="NAV(item.id,item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import advers_list from '../../components/advertisement/advertisement.vue'
	export default {
		data() {
			return {
				keyword: '',
				position: '暂未获取',
				swipers: [{
						id: 1,
						img: "../../static/temp/temp1.jpg"
					},
					{
						id: 2,
						img: "../../static/temp/temp2.jpg"
					},
					{
						id: 3,
						img: "../../static/temp/temp3.jpg"
					}
				],
				navs: [{
						id: 1,
						"icon": "iconfont icon-huabankaobei-",
						"title": "拿快递",
						"path": "/pages/order/order"
					},
					{
						id: 2,
						"icon": "iconfont icon-lingshi",
						"title": "代买餐食",
						"path": "/pagesF/Substitute_food/Substitute_food"
					},
					{
						id: 3,
						"icon": "iconfont icon-dayin",
						"title": "代打印",
						"path": "/pagesC/Generation_printing/Generation_printing"
					},
					{
						id: 4,
						"icon": "iconfont icon-qita",
						"title": "其它",
						"path": "/pagesC/Help_feedback/Help_feedback"
					}
				],
				show: false,
				Search_message: [],
				space: '&nbsp;',
				Search_result: true,
				User: {}
			}
		},
		components: {
			"advers_list": advers_list
		},
		onLoad() {

		},
		methods: {
			NAV(id, path) {
				if (id === 1) {
					uni.switchTab({
						url: `${path}`
					})
				} else {
					uni.navigateTo({
						url: `${path}`
					})
				}
			},
			async change() {
				if (this.keyword == '') {
					return;
				}
				this.show = true;
				// console.log(this.keyword);
				let message = this.keyword;
				let reg;
				let illegal_list = ["/", "\\",
					"[", "]",
					"{", "}",
					"<", ">",
					"＜", "＞",
					"「", "」",
					"：", "；",
					"、", "•",
					"^", "'", "\"",
					"\r", "\r\n", "\\n", "\n"
				];
				for (let i = 0; i < illegal_list.length; i++) {
					if (message.indexOf(illegal_list[i]) >= 0) {
						if (illegal_list[i] == '\\' || illegal_list[i] == '[') {
							reg = new RegExp('\\' + illegal_list[i], "g");
						} else {
							reg = new RegExp(illegal_list[i], "g");
						}
						message = message.replace(reg, '');
					}
				}
				// console.log(message,'1111')
				const res = await this.$myRequest({
					url: `get_SearchMessage?message=${message}`
				})
				// console.log(res);
				if (res.data.code == 0 && res.data.Arr.length != 0) {
					// console.log(res.data.Arr);
					this.Search_result = false;
					this.Search_message = res.data.Arr;
					// console.log(this.Search_message)
				} else {
					this.Search_result = true;
				}
			},
			close() {
				this.Search_message = [];
			},
			nav(id, index) {
				this.User = JSON.parse(uni.getStorageSync('userInfo')) || '{}';
				if ((JSON.stringify(this.User)) == '{}' || this.User === undefined) {
					uni.showToast({
						title: '你还未登录哦',
						icon: 'none'
					})
					uni.navigateTo({
						url: '/pagesD/login_register/login_register'
					})
					return;
				}

				if (this.User.code == 0) {
					if (this.User.message.if_runner == 0) {
						uni.showToast({
							title: '你还不是跑手哦'
						})
						return;
					}
				} else {
					if (this.User.if_runner == 0) {
						uni.showToast({
							title: '你还不是跑手哦'
						})
						return;
					}
				}

				// console.log(id, index)
				uni.navigateTo({
					url: `../../pagesB/details/details?id=${id}&number=${index}`
				})
			}
		},
		onShareAppMessage(res) {
			// console.log('打印一下')
			if (res.from == 'button') {
				// console.log(res.target)
			}
			return {
				title: '分享一下',
				path: '/pages/personal_center/personal_center'
			}
		},
		onShow() {
			this.keyword = '';;
			this.show = false;
		},
		computed: {
			money() {
				return (index) => {
					if (index === '小') {
						return '2元'
					} else if (index === '中') {
						return '3元'
					} else if (index === '大') {
						return '5元'
					} else {
						return '10元'
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	.home {
		width: 750rpx;
		box-sizing: border-box;

		.Search {
			margin-top: 40px;
			margin-bottom: 180px;
			height: 100%;
			box-sizing: border-box;

			.Search_item {
				box-sizing: border-box;
				font-size: 18px;
				display: flex;
				padding: 5px 10px;
				border-bottom: 1px solid #E4E7ED;

				.Search_item_Two {
					height: 50px;
					line-height: 50px;
					font-size: 22px;
					color: #00C2FF;
				}
			}
		}

		.result {
			margin-top: 40px;
			font-size: 25px;
			height: 250px;
			line-height: 250px;
			text-align: center;
			color: #C8C7CC;
		}

		.nav {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			align-items: center;
			margin-top: 20rpx;

			.nav_item {
				width: 50%;
				border-left: 1px solid #eee;
				border-bottom: 1px solid #eee;
				text-align: center;
				// margin-top: 10rpx;
				padding: 20rpx 0;

				view {
					width: 200rpx;
					height: 200rpx;
					margin: 10rpx auto;
					background: $main-color;
					font-size: 140rpx;
					line-height: 200rpx;
					border-radius: 50rpx;
				}

				text {
					padding: 30rpx 0;
					font-size: 36rpx;
					font-weight: 500;
					color: #333333;
				}

				.icon-huabankaobei- {
					color: #FFFFFF;
					background: #2fcb43;
				}

				.icon-lingshi {
					font-size: 200rpx;
					color: #FFFFFF;
					background: #fe4237;
				}

				.icon-dayin {
					color: #FFFFFF;
					background: #ffdd00;
				}

				.icon-qita {
					font-size: 180rpx;
					color: #FFFFFF;
					background: #00a1e9;
				}

			}
		}
	}
</style>
